package com.example.weight.greenSeasons.compost;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.weight.R;
import com.example.weight.config.Config;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import net.cachapa.expandablelayout.ExpandableLayout;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class CompostDailyMaintainActivity extends AppCompatActivity {

    //下拉框
    private ExpandableLayout expandable_1;
    private Button ButtonNo1;
    private ExpandableLayout expandable_2;
    private Button ButtonNo2;
    private ExpandableLayout expandable_3;
    private Button ButtonNo3;

    //日期
    @SuppressLint("SimpleDateFormat")
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// HH:mm:ss
    Date date = new Date(System.currentTimeMillis());

    //操作人，名字角色
    private String name, role, factory;

    //设备复选框
    private CheckBox fandaoji1,dundaixitong2,dundaixitong3,dundaixitong4,hunliaojiaobanluoxuan,hunliaoshusongluoxuan,fuliaoshusongxitong,niliaoshusongluoxuan,baoqixitong,chuchoufengji;
    //设备检查框
    private CheckBox fandaoji1_check,dundaixitong2_check,dundaixitong3_check,dundaixitong4_check,hunliaojiaobanluoxuan_check,hunliaoshusongluoxuan_check,fuliaoshusongxitong_check,niliaoshusongluoxuan_check,baoqixitong_check,chuchoufengji_check;
    //设备备注
    private EditText fandaoji1_remark,dundaixitong2_remark,dundaixitong3_remark,dundaixitong4_remark,hunliaojiaobanluoxuan_remark,hunliaoshusongluoxuan_remark,fuliaoshusongxitong_remark,niliaoshusongluoxuan_remark,baoqixitong_remark,chuchoufengji_remark;

    private Map<String, String> fromIdMap;

    private RequestQueue queue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_compost_daily_maintain);

        //角色
        Intent previousIntent = getIntent();
        name = previousIntent.getStringExtra("name");
        role = previousIntent.getStringExtra("role");
        factory = previousIntent.getStringExtra("factory");
        //日期
        TextView dateText = findViewById(R.id.compost_daily_date);
        dateText.setText(simpleDateFormat.format(date));
        //页面返回按钮
        TitleBar titleBar=findViewById(R.id.titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                CompostDailyMaintainActivity.this.finish();
            }
            @Override
            public void onTitleClick(View v) {
            }
            @Override
            public void onRightClick(View v) {
            }
        });
        //下拉框
        expandable_1=findViewById(R.id.compost_daily_expandable_1);
        ButtonNo1=findViewById(R.id.compost_daily_button1);
        expandable_2=findViewById(R.id.compost_daily_expandable_2);
        ButtonNo2=findViewById(R.id.compost_daily_button2);
        expandable_3=findViewById(R.id.compost_daily_expandable_3);
        ButtonNo3=findViewById(R.id.compost_daily_button3);

        //获取设备控件
        fandaoji1 = findViewById(R.id.compost_daily_fandaoji1);
        dundaixitong2 = findViewById(R.id.compost_daily_dundaixitong2);
        dundaixitong3 = findViewById(R.id.compost_daily_dundaixitong3);
        dundaixitong4 = findViewById(R.id.compost_daily_dundaixitong4);
        fuliaoshusongxitong = findViewById(R.id.compost_daily_fuliaoshusongxitong);
        hunliaojiaobanluoxuan = findViewById(R.id.compost_daily_hunliaojiaobanluoxuan);
        hunliaoshusongluoxuan = findViewById(R.id.compost_daily_hunliaoshusongluoxuan);
        niliaoshusongluoxuan = findViewById(R.id.compost_daily_niliaoshusongluoxuan);
        baoqixitong = findViewById(R.id.compost_daily_baoqixitong);
//        chuchoufengji = findViewById(R.id.compost_daily_chuchoufengji);

        fandaoji1_check = findViewById(R.id.compost_daily_fandaoji1_check);
        dundaixitong2_check = findViewById(R.id.compost_daily_dundaixitong2_check);
        dundaixitong3_check = findViewById(R.id.compost_daily_dundaixitong3_check);
        dundaixitong4_check = findViewById(R.id.compost_daily_dundaixitong4_check);
        fuliaoshusongxitong_check = findViewById(R.id.compost_daily_fuliaoshusongxitong_check);
        hunliaojiaobanluoxuan_check = findViewById(R.id.compost_daily_hunliaojiaobanluoxuan_check);
        hunliaoshusongluoxuan_check = findViewById(R.id.compost_daily_hunliaoshusongluoxuan_check);
        niliaoshusongluoxuan_check = findViewById(R.id.compost_daily_niliaoshusongluoxuan_check);
        baoqixitong_check = findViewById(R.id.compost_daily_baoqixitong_check);
//        chuchoufengji_check = findViewById(R.id.compost_daily_chuchoufengji_check);

        fandaoji1_remark = findViewById(R.id.compost_daily_fandaoji1_remark);
        dundaixitong2_remark = findViewById(R.id.compost_daily_dundaixitong2_remark);
        dundaixitong3_remark = findViewById(R.id.compost_daily_dundaixitong3_remark);
        dundaixitong4_remark = findViewById(R.id.compost_daily_dundaixitong4_remark);
        fuliaoshusongxitong_remark = findViewById(R.id.compost_daily_fuliaoshusongxitong_remark);
        hunliaojiaobanluoxuan_remark = findViewById(R.id.compost_daily_hunliaojiaobanluoxuan_remark);
        hunliaoshusongluoxuan_remark = findViewById(R.id.compost_daily_hunliaoshusongluoxuan_remark);
        niliaoshusongluoxuan_remark = findViewById(R.id.compost_daily_niliaoshusongluoxuan_remark);
        baoqixitong_remark = findViewById(R.id.compost_daily_baoqixitong_remark);
//        chuchoufengji_remark = findViewById(R.id.compost_daily_chuchoufengji_remark);

        fromIdMap = new HashMap<>();

        queue = Volley.newRequestQueue(this);

        setExpandsColor();
        setCheckStatus(fandaoji1, fandaoji1_check);
        setCheckStatus(dundaixitong2, dundaixitong2_check);
        setCheckStatus(dundaixitong3, dundaixitong3_check);
        setCheckStatus(dundaixitong4, dundaixitong4_check);
        setCheckStatus(hunliaojiaobanluoxuan, hunliaojiaobanluoxuan_check);
        setCheckStatus(hunliaoshusongluoxuan, hunliaoshusongluoxuan_check);
        setCheckStatus(fuliaoshusongxitong, fuliaoshusongxitong_check);
        setCheckStatus(niliaoshusongluoxuan, niliaoshusongluoxuan_check);
        setCheckStatus(baoqixitong, baoqixitong_check);
//        setCheckStatus(chuchoufengji, chuchoufengji_check);

        if (role.equals("操作人")) {
            fandaoji1_check.setEnabled(false);
            dundaixitong2_check.setEnabled(false);
            dundaixitong3_check.setEnabled(false);
            dundaixitong4_check.setEnabled(false);
            hunliaojiaobanluoxuan_check.setEnabled(false);
            hunliaoshusongluoxuan_check.setEnabled(false);
            fuliaoshusongxitong_check.setEnabled(false);
            niliaoshusongluoxuan_check.setEnabled(false);
            baoqixitong_check.setEnabled(false);
//            chuchoufengji_check.setEnabled(false);
        }

        // 操作人填表
        fandaoji1.setOnClickListener(v -> {
            if (fandaoji1.isChecked()) {
                operatorAddForm(fandaoji1, fandaoji1_remark.getText().toString());
            }
        });
        dundaixitong2.setOnClickListener(v -> {
            if (dundaixitong2.isChecked()) {
                operatorAddForm(dundaixitong2, dundaixitong2_remark.getText().toString());
            }
        });
        dundaixitong3.setOnClickListener(v -> {
            if (dundaixitong3.isChecked()) {
                operatorAddForm(dundaixitong3, dundaixitong3_remark.getText().toString());
            }
        });
        dundaixitong4.setOnClickListener(v -> {
            if (dundaixitong4.isChecked()) {
                operatorAddForm(dundaixitong4, dundaixitong4_remark.getText().toString());
            }
        });
        hunliaojiaobanluoxuan.setOnClickListener(v -> {
            if (hunliaojiaobanluoxuan.isChecked()) {
                operatorAddForm(hunliaojiaobanluoxuan, hunliaojiaobanluoxuan_remark.getText().toString());
            }
        });
        hunliaoshusongluoxuan.setOnClickListener(v -> {
            if (hunliaoshusongluoxuan.isChecked()) {
                operatorAddForm(hunliaoshusongluoxuan, hunliaoshusongluoxuan_remark.getText().toString());
            }
        });
        fuliaoshusongxitong.setOnClickListener(v -> {
            if (fuliaoshusongxitong.isChecked()) {
                operatorAddForm(fuliaoshusongxitong, fuliaoshusongxitong_remark.getText().toString());
            }
        });
        niliaoshusongluoxuan.setOnClickListener(v -> {
            if (niliaoshusongluoxuan.isChecked()) {
                operatorAddForm(niliaoshusongluoxuan, niliaoshusongluoxuan_remark.getText().toString());
            }
        });
        baoqixitong.setOnClickListener(v -> {
            if (baoqixitong.isChecked()) {
                operatorAddForm(baoqixitong, baoqixitong_remark.getText().toString());
            }
        });
//        chuchoufengji.setOnClickListener(v -> {
//            if (chuchoufengji.isChecked()) {
//                operatorAddForm(chuchoufengji, chuchoufengji_remark.getText().toString());
//            }
//        });
        // 检查人填表
        fandaoji1_check.setOnClickListener(v -> {
            if (fandaoji1_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(fandaoji1.getText().toString())) != null)
                    examinerAddForm(fromId, fandaoji1_remark.getText().toString(), fandaoji1_check);
            }
        });
        dundaixitong2_check.setOnClickListener(v -> {
            if (dundaixitong2_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(dundaixitong2.getText().toString())) != null)
                    examinerAddForm(fromId, dundaixitong2_remark.getText().toString(), dundaixitong2_check);
            }
        });
        dundaixitong3_check.setOnClickListener(v -> {
            if (dundaixitong3_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(dundaixitong3.getText().toString())) != null)
                    examinerAddForm(fromId, dundaixitong3_remark.getText().toString(), dundaixitong3_check);
            }
        });
        dundaixitong4_check.setOnClickListener(v -> {
            if (dundaixitong4_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(dundaixitong4.getText().toString())) != null)
                    examinerAddForm(fromId, dundaixitong4_remark.getText().toString(), dundaixitong4_check);
            }
        });
        hunliaojiaobanluoxuan_check.setOnClickListener(v -> {
            if (hunliaojiaobanluoxuan_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(hunliaojiaobanluoxuan.getText().toString())) != null)
                    examinerAddForm(fromId, hunliaojiaobanluoxuan_remark.getText().toString(), hunliaojiaobanluoxuan_check);
            }
        });
        hunliaoshusongluoxuan_check.setOnClickListener(v -> {
            if (hunliaoshusongluoxuan_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(hunliaoshusongluoxuan.getText().toString())) != null)
                    examinerAddForm(fromId, hunliaoshusongluoxuan_remark.getText().toString(), hunliaoshusongluoxuan_check);
            }
        });
        fuliaoshusongxitong_check.setOnClickListener(v -> {
            if (fuliaoshusongxitong_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(fuliaoshusongxitong.getText().toString())) != null)
                    examinerAddForm(fromId, fuliaoshusongxitong_remark.getText().toString(), fuliaoshusongxitong_check);
            }
        });
        niliaoshusongluoxuan_check.setOnClickListener(v -> {
            if (niliaoshusongluoxuan_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(niliaoshusongluoxuan.getText().toString())) != null)
                    examinerAddForm(fromId, niliaoshusongluoxuan_remark.getText().toString(), niliaoshusongluoxuan_check);
            }
        });
        baoqixitong_check.setOnClickListener(v -> {
            if (baoqixitong_check.isChecked()) {
                String fromId;
                if ((fromId = fromIdMap.get(baoqixitong.getText().toString())) != null)
                    examinerAddForm(fromId, baoqixitong_remark.getText().toString(), baoqixitong_check);
            }
        });
//        chuchoufengji_check.setOnClickListener(v -> {
//            if (chuchoufengji_check.isChecked()) {
//                String fromId;
//                if ((fromId = fromIdMap.get(chuchoufengji.getText().toString())) != null)
//                    examinerAddForm(fromId, chuchoufengji_remark.getText().toString(), chuchoufengji_check);
//            }
//        });
    }
    public void show1(View view) {
        if (expandable_1.isExpanded()){
            ButtonNo1.setText("+ 检查运行状况擦拭表面卫生");
        }else{
            ButtonNo1.setText("- 检查运行状况擦拭表面卫生");
        }
        expandable_1.toggle();
    }
    public void show2(View view) {
        if (expandable_2.isExpanded()){
            ButtonNo2.setText("+ 擦拭卫生");
        }else{
            ButtonNo2.setText("- 擦拭卫生");
        }
        expandable_2.toggle();
    }
    public void show3(View view) {
        if (expandable_3.isExpanded()){
            ButtonNo3.setText("+ 检查运行状况");
        }else{
            ButtonNo3.setText("- 检查运行状况");
        }
        expandable_3.toggle();
    }

    //功能相关
    private void examinerAddForm(String formId, String comment, CheckBox checkBox) {
        new AlertDialog.Builder(this)
                .setTitle("确定检查吗？")
                .setCancelable(false)
                .setNegativeButton("取消", ((dialog, which) -> checkBox.setChecked(false)))
                .setPositiveButton("确定", (dialog, which) -> {
                    checkBox.setEnabled(false);
                    String url = Config.url + "/shlj/sjqCompostProduceMaintenance/add_day_inspector";
                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");

                                        if (code.startsWith("2"))
                                            Toast.makeText(CompostDailyMaintainActivity.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        else
                                            Toast.makeText(CompostDailyMaintainActivity.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(CompostDailyMaintainActivity.this,
                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() {
                            Map<String, String> map=new HashMap<>();
                            map.put("id", formId);
                            map.put("Inspector", name);
                            map.put("remarks", comment);
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                }).show();
    }
    private void operatorAddForm(CheckBox checkBox, String comment) {
        String fName = checkBox.getText().toString();
        String maintainstr;
        switch (fName) {
            case "1#混料机":
            case "2#混料机":
            case "3#混料机":
            case "4#混料机":
                maintainstr="检查运行状况擦拭表面卫生";
                break;
            case "辅料输送系统":
            case "混料搅拌螺旋":
            case "混料输送螺旋":
            case "泥料输送螺旋":
                maintainstr="擦拭卫生";
                break;
            case "航吊":
                maintainstr="检查运行状况";
                break;
            default:
                maintainstr="";
                break;
        }
        String maintainContent=maintainstr;
        new android.app.AlertDialog.Builder(this)
                .setTitle("确定提交吗？")
                .setCancelable(false)
                .setNegativeButton("取消", ((dialog, which) -> checkBox.setChecked(false)))
                .setPositiveButton("确定", (dialog, which) -> {
                    checkBox.setEnabled(false);
                    String url = Config.url + "/shlj/sjqCompostProduceMaintenance/add_day_recorder";
                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");

                                        if (code.startsWith("2"))
                                            Toast.makeText(CompostDailyMaintainActivity.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        else
                                            Toast.makeText(CompostDailyMaintainActivity.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(CompostDailyMaintainActivity.this,
                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() {
                            Map<String, String> map=new HashMap<>();
                            map.put("equipment_name", fName);
                            map.put("maintenanceContent", maintainContent);
                            map.put("isNormal", comment.equals("")?"1":"0");
                            map.put("remarks", comment);
                            map.put("operator", name);
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                }).show();
    }
    private void setCheckStatus(CheckBox operatorCB, CheckBox examinerCB) {
        String fName = operatorCB.getText().toString();
        String maintainContent;
        switch (fName) {
            case "1#混料机":
            case "2#混料机":
            case "3#混料机":
            case "4#混料机":
                maintainContent="检查运行状况擦拭表面卫生";
                break;
            case "辅料输送系统":
            case "混料搅拌螺旋":
            case "混料输送螺旋":
            case "泥料输送螺旋":
                maintainContent="擦拭卫生";
                break;
            case "堆肥车间曝气系统":
            case "堆肥车间除臭风机":
                maintainContent="检查运行状况";
                break;
            default:
                maintainContent="";
                break;
        }

        String url = Config.url + "/shlj/sjqCompostProduceMaintenance/getlast_day";
        String finalMaintainContent = maintainContent;
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            if (!jsonObject.isNull("data")) {
                                JSONObject data = jsonObject.getJSONObject("data");
                                operatorCB.setChecked(true);
                                operatorCB.setEnabled(false);
                                operatorCB.setTextColor(Color.GREEN);
                                setRemarks(operatorCB, data.getString("remarks"));

                                String examiner = data.getString("inspector");
                                if (!examiner.equals("") && !examiner.equals("null")) {
                                    // 检查人已检查某项，该项不可再检查
                                    examinerCB.setChecked(true);
                                    examinerCB.setEnabled(false);
                                    examinerCB.setTextColor(Color.GREEN);
                                } else {
                                    // 若存在检查人未检查项，将其添加到formIdList中
                                    fromIdMap.put(fName, data.getString("id"));
                                }
                            } else {
                                if (role.equals("检查人")) {
                                    // 如果操作人未保养，检查人不可检查
                                    operatorCB.setEnabled(false);
                                    examinerCB.setEnabled(false);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(CompostDailyMaintainActivity.this,
                        "失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> map=new HashMap<>();
                map.put("equipment_name", fName);
                map.put("maintenanceContent", finalMaintainContent);
                map.put("factory", factory);
                return map;
            }
        };
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(stringRequest);
    }
    private void setRemarks(CheckBox checkBox, String remarks) {
        switch (checkBox.getText().toString()) {
            case "1#混料机":
                fandaoji1_remark.setText(remarks);
                break;
            case "2#混料机":
                dundaixitong2_remark.setText(remarks);
                break;
            case "3#混料机":
                dundaixitong3_remark.setText(remarks);
                break;
            case "4#混料机":
                dundaixitong4_remark.setText(remarks);
                break;
            case "混料搅拌螺旋":
                hunliaojiaobanluoxuan_remark.setText(remarks);
                break;
            case "混料输送螺旋":
                hunliaoshusongluoxuan_remark.setText(remarks);
                break;
            case "辅料输送系统":
                fuliaoshusongxitong_remark.setText(remarks);
                break;
            case "泥料输送螺旋":
                niliaoshusongluoxuan_remark.setText(remarks);
                break;
            case "堆肥车间曝气系统":
                baoqixitong_remark.setText(remarks);
                break;
            default:
//                chuchoufengji_remark.setText(remarks);
                break;
        }
    }

    public void setExpandsColor() {
        String url = Config.url + "/shlj/sjqCompostProduceMaintenance/is_day_complete";
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            if (!jsonObject.isNull("data")) {
                                JSONArray data = jsonObject.getJSONArray("data");
                                setExpandColor(data);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(CompostDailyMaintainActivity.this,
                        "失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> map=new HashMap<>();
                map.put("equipmentsName", "1#混料机_2#混料机_3#混料机_4#混料机_辅料输送系统_混料搅拌螺旋_混料输送螺旋_泥料输送螺旋_堆肥车间曝气系统_堆肥车间除臭风机");
                map.put("menstanceNum", "1_1_1_1_1_1_1_1_1_1");
                map.put("role", role.equals("操作人")?"operator":"examiner");
                map.put("factory", factory);
                return map;
            }
        };
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(stringRequest);
    }

    private void setExpandColor (JSONArray array) throws JSONException {
        if (array.getInt(0) == 2 && array.getInt(1) == 2 &&
                array.getInt(2) == 2 && array.getInt(3) == 2) {
            ButtonNo1.setTextColor(Color.GREEN);
        } else if (array.getInt(0) == 1 && array.getInt(1) == 1 &&
                array.getInt(2) == 1 && array.getInt(3) == 1) {
            ButtonNo1.setTextColor(Color.YELLOW);
        }
        if (array.getInt(4) == 2 && array.getInt(5) == 2 &&
                array.getInt(6) == 2 && array.getInt(7) == 2) {
            ButtonNo2.setTextColor(Color.GREEN);
        } else if (array.getInt(4) == 1 && array.getInt(5) == 1 &&
                array.getInt(6) == 1 && array.getInt(7) == 1) {
            ButtonNo2.setTextColor(Color.YELLOW);
        }
        if (array.getInt(8) == 2 && array.getInt(9) == 2) {
            ButtonNo3.setTextColor(Color.GREEN);
        } else if (array.getInt(8) == 1 && array.getInt(9) == 1) {
            ButtonNo3.setTextColor(Color.YELLOW);
        }
    }
}